import {IMyObject, MyObject} from "./MyObject";
import {Grade, IGrade} from "./Grade";
import { SubjectType } from "./Subject";

export interface IStudent extends IMyObject{
  id: number;

  getGrade(type:SubjectType):IGrade | undefined
  getGradeString(type:SubjectType) :string

  setGradeByType(type:SubjectType, num: number):void
  setGrade(grade:IGrade):void
}

export class Student extends MyObject  implements IStudent {
  id = 0;

  private grades: Map<SubjectType,IGrade> = new Map<SubjectType,IGrade>();

  constructor(id: number, name: string) {
    super(name);
    this.id = id;
  }

  getGrade(type: SubjectType): IGrade | undefined {
    return this.grades.get(type);
  }

  getGradeString(type: SubjectType): string {
    const grade = this.getGrade(type);
    return grade ? grade.toString() : "无"
  }

  setGrade(grade: IGrade): void {
    this.grades.set(grade.type,grade)
  }

  setGradeByType(type: SubjectType, num: number): void {
    const grade = new Grade(type,num);
    this.setGrade(grade)
  }

  toString(): string {
    return this.name + ":" + this.id;
  }



}